package com.tjsinfo.tjsoa.fileExpress.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.criterion.DetachedCriteria;

import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.fileExpress.bo.IFileExpressFileBo;
import com.tjsinfo.tjsoa.system.bo.ISystemUserBo;
import com.tjsinfo.tjsoa.system.vo.TSystemUser;

public class CreateUserFileAction extends Action{
	private IQbcDao qbcDao;
	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		
		ResourceBundle bundle = ResourceBundle.getBundle("com.tjsinfo.tjsoa.fileExpress.properties.FileExpress");
		String path = bundle.getString("fileupload");
		
		DetachedCriteria criteria = DetachedCriteria.forClass(TSystemUser.class);
		ArrayList list = (ArrayList)qbcDao.getCriteria(criteria);
		for (Iterator iterator = list.iterator(); iterator.hasNext();) {
			TSystemUser user = (TSystemUser) iterator.next();
			java.io.File  myFilePath  =  new  java.io.File(path+user.getUuid());  
	        if  (!myFilePath.exists())  {  
	        	String strdos = "cmd /c md \""+path+user.getUuid()+"\"";
	        	Process process;
				try {
					process = Runtime
							.getRuntime().exec(strdos);
					process.waitFor();
					strdos = "cmd /c md \""+path+user.getUuid()+"\\download\\\"";
					process = Runtime
					.getRuntime().exec(strdos);
			process.waitFor();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	        } 
		}
		
		return mapping.findForward("success");
	}
}
